//
//  UILabel＋Extension.swift
//  Weibo
//
//  Created by 冯童童 on 16/1/17.
//  Copyright © 2016年 冯童童. All rights reserved.
//

import UIKit

extension UILabel {
    
    class  func labelFactory(title : String, fontSize : CGFloat, color : UIColor) -> UILabel {
        let l = UILabel()
        
        l.text = title
        l.font = UIFont.systemFontOfSize(fontSize)
        l.textColor = color 
        l.sizeToFit()
        l.textAlignment = .Center
        l.numberOfLines = 0
        
        return l
    }
    
    convenience init(title : String, fontSize : CGFloat, color : UIColor, margin : CGFloat = 0){
        self.init()
        font = UIFont.systemFontOfSize(fontSize)
        text = title
        numberOfLines = 0
        textColor = color
        textAlignment = .Center
        if margin > 0 {
            textAlignment = .Left
            preferredMaxLayoutWidth = KWidth - 2 * margin
        }
        sizeToFit()
    }
    
    
}
